/*
https://leetcode.cn/problems/longest-substring-without-repeating-characters/
03.无重复字符的最长子串
medium, 李佳韵 2024.08.29
滑动窗口
*/

#pragma once

#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        unordered_map<char, int> n;
        int ans = 0, i = 0;
        for (int j = 0; j < s.size(); ++j) {
            if (n.find(s[j]) != n.end())
                i = max(i, n[s[j]] + 1);
            n[s[j]] = j;
            ans = max(ans, j - i + 1);
        }
        return ans;
    }
};

int main() {
    Solution solution;
    string s = "abcabcbb";
    cout << "最小子串长度为：" << solution.lengthOfLongestSubstring(s) << endl;
    return 0;
}